clear 


set matsize 2000

use "$Replicationdirectory/_Work/TEMP/DAWES_PANEL_ytm"
	
	preserve
		keep if market=="london"
		keep date tradingday_london
			
			save "$Replicationdirectory/_Work/TEMP/trading_days_london", replace  
	restore 
	


 
  		drop if tradingday_london==.					

* Estimate ROLL for Dawes 
		
		
		* Roll's effective spread measure  (in %)
		
				
				
				*
				gen ln_closing=ln(Price_GBP_lastvail)					
				by market_enc: gen Current_return=ln_closing-ln_closing[_n-1]		 
				by market_enc: gen L1_return=Current_return[_n-1]
				
				
				 			
				rangestat (cov) Current_return L1_return, by(market_enc) interval(date -21 0)

				replace cov_x=0 if cov_x>0
		
		
				gen ROLL=200*sqrt(-cov_x) 
				
				
 				
				
				
				
				

		* export daily 
		
			preserve 
			
			keep ROLL default market date
			
							save "$Replicationdirectory/_Work/TEMP/ROLL_daily" , replace 
								
								
								* export London only
									keep if market=="london"
									rename ROLL ROLLlondon
											
									gen bond="Dawes"
									
									save "$Replicationdirectory/_Work/TEMP/ROLL_LOONDON_daily" , replace 
				restore 
		
		  
 
 
 		 
* Estimate ROLL for Consol 


	clear
	
		use "$Replicationdirectory/_Work/TEMP/_data_consol_daily_panel"
		
		
		merge m:1 date using "$Replicationdirectory/_Work/TEMP/trading_days_london"
		
		drop if _merge==2
		
  		drop if tradingday_london==.					
		
		
		
		encode market, gen(market_enc)
		
		xtset market_enc date 
		
			*create dummy for default
											gen default=1 if date>td(14jun1934)
											replace default=0 if default==.
											
											
 		
		
		* Roll's effective spread measure  (in %)
		
				
				
				*
				gen ln_closing=ln(P_lastavail_consol)					
				by market_enc: gen Current_return=ln_closing-ln_closing[_n-1]		 
				by market_enc: gen L1_return=Current_return[_n-1]
				
				
				 			
				rangestat (cov) Current_return L1_return, by(market_enc) interval(date -21 0)

				replace cov_x=0 if cov_x>0
		
		
				gen ROLL=200*sqrt(-cov_x) 

 
		* daily london only 
		 
		
		 		preserve 
				
									keep if market=="london"
								
									keep date P_lastavail_consol ROLL
									 
									gen y_consol_London=100* 2.5/P_lastavail_consol
									
									gen ROLL_consol_london=ROLL
									
									keep y_consol_London ROLL_consol_london date 
												
								save "$Replicationdirectory/_Work/TEMP/ROLL_consol_daily_londononly" , replace 
								
							  
								 
				restore 
				
		
		* daily both markets 
			  
			 preserve 
 
						keep date P_lastavail_consol ROLL market
						
 						gen cy_consol=100* 2.5/P_lastavail_consol
									
									gen ROLL_consol=ROLL
									
									keep cy_consol ROLL_consol date 
												
 							
 								
												gen bond="Consol"

												
												
								save "$Replicationdirectory/_Work/TEMP/ROLL_consol_daily_londonparis" , replace 
								
							  
								 
				restore 
		

**** Generate liquidty spreads over London



clear

	*** load relevant data
				
				
				* gen monthly bond spread dataset
						 use "$Replicationdirectory/_Work/TEMP/DAWES_PANEL_ytm"   
						
						  gen dw = wofd(date)
						  gen dy = yofd(date)
						  
						  gen dm = mofd(date)
						  
						  
		 

		  
						
						merge 1:1 date market using "$Replicationdirectory/_Work/TEMP/ROLL_daily" 
						
						
						
						 
						gen bond="Dawes"
									 
							 
										drop _merge
										
						merge m:1 date     using 		"$Replicationdirectory/_Work/TEMP/ROLL_consol_daily_londononly" 
												drop _merge

						 
						
										
						merge m:1 date   bond using 		"$Replicationdirectory/_Work/TEMP/ROLL_LOONDON_daily"
						
				
				
				* calculates liqudity spread only for trading days
						drop if _merge!=3
						drop _merge
						
						
						
						
						
						xtset market_enc date
				
				* gen liquidity spread
				
				
				  
					gen spread_liquidity= ROLL-ROLLlondon
					
					preserve
					keep date spread_liquidity market
					
					label var spread_liquidity "Bid-ask spread relative to London bid-ask spread"
					
					save "$Replicationdirectory/_Work/TEMP/Liquidity_spreads", replace
					
					restore 
					
					
		
		
		 
					 
 
*** ADD ROLL LIQUIDITY MEAUSRE 		to panel		

				use "$Replicationdirectory/_Work/TEMP/DAWES_PANEL_ytm"   ,clear 


				merge 1:1 market date using "$Replicationdirectory/_Work/TEMP/Liquidity_spreads"	

				drop _merge


				merge 1:1 market date using "$Replicationdirectory/_Work/TEMP/ROLL_daily"

				drop _merge 

				merge m:1 date using "$Replicationdirectory/_Work/TEMP/ROLL_consol_daily_londononly"
				drop _merge 

				 

				save "$Replicationdirectory/_Work/TEMP/PANEL_incl_liquidity_ytm"			, replace
